package com.liuyjy.es.wrapper;


import com.liuyjy.utils.utils.LambdaUtils;
import com.liuyjy.utils.utils.SFunction;

import java.lang.reflect.ParameterizedType;
import java.util.function.Consumer;

/**
 * @Author liuyjy
 * @Date 2025/2/25 12:08
 * @Description: TODO
 **/
public class EsLambdaQueryWrapper<T> extends EsBaseWrapper<T, SFunction<T, ?>, EsLambdaQueryWrapper<T>> {


    public EsLambdaQueryWrapper() {
        this((T)null);
    }

    public EsLambdaQueryWrapper(T entity) {
        super.setEntity(entity);
    }

    public EsLambdaQueryWrapper(Class<T> entityClass) {
        super.setEntityClass(entityClass);
    }


    @Override
    protected EsLambdaQueryWrapper<T> self() {
        return this;
    }

    protected String columnToString(SFunction<T, ?> column) {
        return LambdaUtils.resolve(column);
    }

    /**
     * 多字段转换为逗号 "," 分割字符串
     *
     * @param columns 多字段
     */
    protected String[] columnsToString(SFunction<T, ?>... columns) {
        return LambdaUtils.resolve(columns);
    }

    @Override
    protected EsLambdaQueryWrapper<T> and(Consumer<EsLambdaQueryWrapper<T>> consumer) {
        EsLambdaQueryWrapper<T> wrapper = new EsLambdaQueryWrapper<>();
        consumer.accept(wrapper);
        boolQuery.must(wrapper.boolQuery);
        return self();
    }

    @Override
    protected EsLambdaQueryWrapper<T> or(Consumer<EsLambdaQueryWrapper<T>> consumer) {
        EsLambdaQueryWrapper<T> wrapper = new EsLambdaQueryWrapper<>();
        consumer.accept(wrapper);
        boolQuery.should(wrapper.boolQuery);
        return self();
    }


}
